package com.wtwd.device.handler.processimpl;


import com.wtwd.device.annotation.MsgType;
import com.wtwd.device.constant.Constant;
import com.wtwd.device.constant.MsgTypeEnum;
import com.wtwd.device.handler.MsgHandlerFactory;
import com.wtwd.device.handler.ProcessMessageHandler;
import com.wtwd.device.mqtentity.MessageBase;
import com.wtwd.device.netty.LocalSessions;
import com.wtwd.device.properties.MqProperties;
import com.wtwd.device.protocol.AppProtocol;
import io.netty.channel.Channel;

/**
 * 设备离线
 */
@MsgType(MsgTypeEnum.APP_OFFLINE)
public class OfflineHandle implements ProcessMessageHandler {



    @Override
    public AppProtocol processMsg(AppProtocol appProtocol, Channel channel) {
        String deviceKey = LocalSessions.removeByChannel(channel);
        appProtocol.setImei(deviceKey);
        MsgHandlerFactory.getMqSendMessage()
                .push(
                        MessageBase.builder()
                                .deviceKey(deviceKey)
                                .appProtocol(appProtocol)
                                .form(MqProperties.getAppTopic())
                                .type(Constant.APP_MSG)
                                .build());
        return null;
    }
}
